<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link href="../../build/common/base.css" rel="stylesheet">
    
  <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css"> <link
    rel="stylesheet" href="../../build/form/form.css">
  <link rel="stylesheet" href="../../build/form/page.css">
  <script type="text/javascript" src="../../build/common/base.js"></script>
  <script type="text/javascript" src="../../build/common/vueEdit.js"></script>
  <script src="../../assets/js/common/element/index.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/bootstrap-table.js"></script>
  <style>
    * {
      padding: 0px;
      margin: 0px;
    }

    ul li {
      list-style: none;
    }

    .my_cols {
      margin: 20px 0;
    }
  </style>
</head>

<body>
  <div id="ctrlC" style="padding: 30px;">
    <!-- <div class="consea">隐藏相同项</div> -->
    <span @click="handYes()" class="btn btn-success mb30 mr15">隐藏相同项</span>
    <span @click="handAdd()" class="btn btn-success mb30">添加</span>
    <table id="table">

    </table>
  </div>
</body>
<div id="ceshi"></div>
<script type="text/javascript">










  var vm = new Vue({
    el: "#ctrlC",
    data: function () {
      return {
        duibiList: [],
        columnlist: [],
        datalist: [],
        columnsArray: []
      }
    },
    beforeCreate: function () {
    },
    mounted: function () {


      window.addEventListener('unload', e => this.unloadHandler(e))
      this.add()
      window.addEventListener('beforeunload', e => {
        sessionStorage.removeItem("xuanzhongid")
        sessionStorage.removeItem("xuanzhongname")
      })
      let me = this;
      window['add'] = () => {
        me.add()
        // Toast({ message: url, position: 'bottom', duration: 5000 });
        console.log("???????????????")
      }

    },

    created: function () {
      // $.getResultData(post, function (data) {
      //   console.log("对比参数", data)
      //   // that.veList = data.list
      // });
    },
    methods: {
      unloadHandler: function () {
        sessionStorage.removeItem("xuanzhongid")
        sessionStorage.removeItem("xuanzhongname")
        // this._gap_time=new Date().getTime()-this._beforeUnload_time
        console.log("guanbilemamamamamam")
      },
      add: function () {
        //销毁表格从新渲染
        $('#table').bootstrapTable('destroy');
        // var columnlist = []
        // var datalist = []
        // var columnsArray = []
        var that = this
        var ids = location.search.replace("?", "")
        // sessionStorage.getItem("xuanzhongid")
        // sessionStorage.getItem("xuanzhongname")
        var url = Vue.__ctx + "/sys/paramCompare/compareParams/" + sessionStorage.getItem("arrstr") + "&" + sessionStorage.getItem("xuanzhongid") + "/" + sessionStorage.getItem("arrcpmcstr") + "&" + sessionStorage.getItem("xuanzhongname");
        $.ajax({
          url: url,
          type: 'get',
          // async: true, //或false,是否异步
          success: function (res) {
            that.$nextTick(function () {
              res = JSON.parse(res)
              console.log(res, "===")
              that.columnlist = res.clist;
              that.datalist = res.datalist;
              that.columnsArray = [];
              that.columnsArray.push({ field: "state", checkbox: true });
              for (var i = 0; i < that.columnlist.length; i++) {//Object.keys(obj) 获取key名称
                var property = that.columnlist[i];//id   username
                that.columnsArray.push({
                  "title": property.title,
                  "field": property.field,
                  switchable: true,
                  sortable: true
                });

              }
              $('#table').bootstrapTable({
                data: that.datalist,
                // toolbar: '#toolbar',
                // singleSelect: true,
                // clickToSelect: true,
                pageSize: 15,
                pageNumber: 1,
                pageList: "[10, 25, 50, 100, All]",
                // showToggle: true,
                // showRefresh: true,
                // showColumns: true,
                // search: true,
                pagination: true,
                columns: that.columnsArray
              });

            })
          }

        })
        // var post = Vue.baseService.get(url);
        // post.then(function (res) {

        // }, function (status) {
        //   if (status == !0) {
        //     $.Toast.error('加载失败！' + status);
        //   }
        // })
      },
      handAdd: function () {
        var index = layer.open({
          type: 2,
          content: "./add.html?" + location.search.replace("?", ""),
          area: ['320px', '195px'],
          maxmin: true,
          // success: function () {
          //   $(".but_par").click(function () {
          //     alert(222);
          //   })
          // }
        });
        layer.full(index);
      },
      handYes: function () {
        console.log("隐藏相同项", this.datalist)
        if (this.datalist.length) {
          var tab = $("#table tbody tr")
          var arr = []
          for (var k = 0; k < tab.length; k++) {
            arr.push(tab[k])
          }
          for (var i = 0; i < arr.length; i++) {
            var abc = Array.from(arr[i].children)
            abc.splice(0, 2)
            // abc.splice(-1, 1)
            console.log("wwww", abc)
            var result = abc.every(function (item) {
              return abc[0].innerHTML == item.innerHTML
            })
            if (result == true) {
              $(tab[i]).toggle();
            }
          }
        }

      },
    },

    watch: {

    }
  });
</script>

</html>